/**
 * Proyecto: Cognitum
 * Global IT Services 2008
 * @author Esanantonio
 */

Cognitum.Negociacion.Editor = Ext.extend(Karma.EBCard, {

    initComponent: function() {
        Ext.apply(this, {
            sections: [{
                title: 'Generales',
                items: [{
                    xtype: 'entity.link',
                    entityName: 'Clientes',
                    fieldLabel: 'Cliente',
                    name: 'Cliente'
                }, {
                    xtype: 'entity.link',
                    entityName: 'Aseguradoras',
                    fieldLabel: 'Aseguradora',
                    name: 'Aseguradora'
                }, {
                    xtype: 'entity.link',
                    entityName: 'Ramos',
                    fieldLabel: 'Ramo',
                    name: 'Ramo'
                }, {
                    fieldLabel: '% Comision',
                    name: 'ComisionPct'
                }, {
                    fieldLabel: '% Bono',
                    name: 'BonoPct'
                }, {
                    fieldLabel: '% Sobrecomision',
                    name: 'SobrecomisionPct'
                }, {
                    fieldLabel: 'PNA Aproximada',
                    name: 'PrimaNetaAproximada'
                }, {
                    fieldLabel: 'Dias Negociados de Entrega',
                    name: 'DiasNegociadosEntrega'
}]
                }, {
                    title: 'Polizas',
                    items: [
	                {
	                    hideLabel: true,
	                    name: 'Polizas',
	                    entityName: 'Polizas',
	                    xtype: 'entity.list',
	                    selectionConfig: {
	                        multiSelect: true,
	                        width: 700
	                    },
	                    context: 'p.Negociacion.Id=? ',
	                    anchor: '100% 100%',
	                    onBeforeAdd: function(ids, data, liquidacion) {
	                        if (Ext.isEmpty(liquidacion)) {
	                            return;
	                        }
	                        Ext.MessageBox.show({
	                            msg: 'Procesando...',
	                            progressText: 'Saving...',
	                            width: 300,
	                            wait: true,
	                            waitConfig: { interval: 200 }
	                        });
	                        this.entity.useInvoker('DoAsignaPoliza', [ids, liquidacion.Id], {
	                            fn: function() {
	                                this.reload();
	                                this.fireEvent('beforeadd');
	                                Ext.MessageBox.hide();
	                            },
	                            scope: this
	                        });
	                    },
	                    onBeforeDelete: function(id) {
	                        if (Ext.isEmpty(id)) {
	                            return;
	                        }
	                        Ext.MessageBox.show({
	                            msg: 'Procesando...',
	                            progressText: 'Saving...',
	                            width: 300,
	                            wait: true,
	                            waitConfig: { interval: 200 }
	                        });
	                        this.entity.useInvoker('DoDesasignaPoliza', id, {
	                            fn: function() {
	                                this.reload();
	                                this.fireEvent('beforedelete');
	                                Ext.MessageBox.hide();
	                            },
	                            scope: this
	                        });
	                    }
	                }
		        ]
                }, {
                    xtype: 'sec.editor',
                    title: 'Seguridad'
                }, {
                    xtype: 'aud.editor',
                    title: 'Auditoria'
}]
                });
                Cognitum.Negociacion.Editor.superclass.initComponent.apply(
			this, arguments);
            }

        });

Ext.reg('neg.editor', Cognitum.Negociacion.Editor);
